﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI.WebControls;
using MinhTuan;
namespace Products
{
    public class Product
    {
        #region attribute
            private Int32 _Products_Id;
            private String _Products_Name;
            private String _Products_Title;
            private Int32 _Products_Quantity;
            private Int32 _Products_Price;
            private String _Products_Unit;
            private Int32 _Class_Id;
            private Int32 _Brand_Id;
            private Int32 _Category_Id;
            private String _Products_Detail;
            private String _Products_Warranty;
            private String _Products_Image;
            private String _Products_Origin;
            private String _Products_DescriptionImage;
            private DateTime _Products_DateUpdate;
            private Boolean _IsActive;
            private Boolean _Ishot;
            private Boolean _IsNew;

        #endregion
        #region  Constructor
                    public Product()
                    {

                    }
                    public Product(
			            Int32 Products_Id,
			            String Products_Name,
			            String Products_Title,
			            Int32 Products_Quantity,
			            Int32 Products_Price,
			            String Products_Unit,
			            Int32 Class_Id,
			            Int32 Brand_Id,
			            Int32 Category_Id,
			            String Products_Detail,
			            String Products_Warranty,
			            String Products_Image,
			            String Products_Origin,
			            String Products_DescriptionImage,
			            DateTime Products_DateUpdate,
			            Boolean IsActive,
			            Boolean Ishot,
			            Boolean IsNew
                        )
                    {		_Products_Id=Products_Id;
		            _Products_Name=Products_Name;
		            _Products_Title=Products_Title;
		            _Products_Quantity=Products_Quantity;
		            _Products_Price=Products_Price;
		            _Products_Unit=Products_Unit;
		            _Class_Id=Class_Id;
		            _Brand_Id=Brand_Id;
		            _Category_Id=Category_Id;
		            _Products_Detail=Products_Detail;
		            _Products_Warranty=Products_Warranty;
		            _Products_Image=Products_Image;
		            _Products_Origin=Products_Origin;
		            _Products_DescriptionImage=Products_DescriptionImage;
		            _Products_DateUpdate=Products_DateUpdate;
		            _IsActive=IsActive;
		            _Ishot=Ishot;
		            _IsNew=IsNew;
                    }
                   
        	            public Int32 Products_Id
	                {
	                  get { return _Products_Id; }
	                  set { _Products_Id = value; }
	                 }

	            public String Products_Name
	                {
	                  get { return _Products_Name; }
	                  set { _Products_Name = value; }
	                 }

	            public String Products_Title
	                {
	                  get { return _Products_Title; }
	                  set { _Products_Title = value; }
	                 }

	            public Int32 Products_Quantity
	                {
	                  get { return _Products_Quantity; }
	                  set { _Products_Quantity = value; }
	                 }

	            public Int32 Products_Price
	                {
	                  get { return _Products_Price; }
	                  set { _Products_Price = value; }
	                 }

	            public String Products_Unit
	                {
	                  get { return _Products_Unit; }
	                  set { _Products_Unit = value; }
	                 }

	            public Int32 Class_Id
	                {
	                  get { return _Class_Id; }
	                  set { _Class_Id = value; }
	                 }

	            public Int32 Brand_Id
	                {
	                  get { return _Brand_Id; }
	                  set { _Brand_Id = value; }
	                 }

	            public Int32 Category_Id
	                {
	                  get { return _Category_Id; }
	                  set { _Category_Id = value; }
	                 }

	            public String Products_Detail
	                {
	                  get { return _Products_Detail; }
	                  set { _Products_Detail = value; }
	                 }

	            public String Products_Warranty
	                {
	                  get { return _Products_Warranty; }
	                  set { _Products_Warranty = value; }
	                 }

	            public String Products_Image
	                {
	                  get { return _Products_Image; }
	                  set { _Products_Image = value; }
	                 }

	            public String Products_Origin
	                {
	                  get { return _Products_Origin; }
	                  set { _Products_Origin = value; }
	                 }

	            public String Products_DescriptionImage
	                {
	                  get { return _Products_DescriptionImage; }
	                  set { _Products_DescriptionImage = value; }
	                 }

	            public DateTime Products_DateUpdate
	                {
	                  get { return _Products_DateUpdate; }
	                  set { _Products_DateUpdate = value; }
	                 }

	            public Boolean IsActive
	                {
	                  get { return _IsActive; }
	                  set { _IsActive = value; }
	                 }

	            public Boolean Ishot
	                {
	                  get { return _Ishot; }
	                  set { _Ishot = value; }
	                 }

	            public Boolean IsNew
	                {
	                  get { return _IsNew; }
	                  set { _IsNew = value; }
	                 }
             
        #endregion
        #region  Method
                public static DataTable GetAll()
                {
                    DataTable tbl = new DataTable();
                    try
                    {
                        Access.InitAccess();
                        Access.mySqlCommand.CommandText = "Sp_Products_GetAll";
                        SqlDataAdapter da = new SqlDataAdapter(Access.mySqlCommand);
                        DataSet ds = new DataSet();
                        da.Fill(ds);
                        Access.ClosedAccess();
                        return ds.Tables[0];

                    }
                    catch
                    {
                        Access.ClosedAccess();
                        return tbl;
                    }

                }
                public static void Buildmenu( DataList dtlist,int Category_Id)
                {
                    try {
                        Access.InitAccess();
                        Access.mySqlCommand.CommandText = "sp_Product_GetBandByMenu";
                        Access.mySqlCommand.Parameters.Add("@Category_Id", SqlDbType.Int).Value = Category_Id;
                        SqlDataAdapter da = new SqlDataAdapter(Access.mySqlCommand);
                        DataSet ds = new DataSet();
                        da.Fill(ds);
                        Access.ClosedAccess();
                        dtlist.DataSource = ds.Tables[0];

                    }
                    catch
                    {
                        Access.ClosedAccess();
                    }
                    
                }
                public static void Buildmenu( Literal menu)
                {
                    String buildmenu="";
                    try
                    {
                        Access.InitAccess();
                        Access.mySqlCommand.CommandText = "Sp_BuildMenu";
                        SqlDataReader myreader;
                        myreader = Access.mySqlCommand.ExecuteReader();
                        while (myreader.Read())
                        {
                            buildmenu = myreader["Menustring"].ToString();
                        }
                        menu.Text = buildmenu;
                        Access.ClosedAccess();
                        
                    }
                    catch
                    {
                        Access.ClosedAccess();
                    }

                }
                public static DataTable GetProductByBrand(Int32 brand_id)
                { 
                    DataTable tbl =new DataTable();
                    //try
                    //{
                    //    Access.InitAccess();
                    //    Access.mySqlCommand.CommandText = "Sp_Products_GetProductByBrand";
                    //    Access.mySqlCommand.Parameters.Add("@Brand_Id", SqlDbType.Int).Value = brand_id;
                    //    SqlDataAdapter da = new SqlDataAdapter(Access.mySqlCommand);
                    //    DataSet ds = new DataSet();
                    //    da.Fill(ds);
                    //    Access.ClosedAccess();
                    //    return ds.Tables[0];

                    //}
                    //catch
                    //{
                    //    Access.ClosedAccess();
                    //    return tbl;
                    //}
                    tbl = Access.GetData("Sp_Products_GetProductByBrand", "@Brand_Id", brand_id, SqlDbType.Int);
                    return tbl;

                }
                public static DataTable GetProductByBrandEdit(Int32 brand_id)
                {
                    DataTable tbl = new DataTable();
                    try
                    {
                        Access.InitAccess();
                        Access.mySqlCommand.CommandText = "Sp_Products_GetProductByBrandToedit";
                        Access.mySqlCommand.Parameters.Add("@Brand_Id", SqlDbType.Int).Value = brand_id;
                        SqlDataAdapter da = new SqlDataAdapter(Access.mySqlCommand);
                        DataSet ds = new DataSet();
                        da.Fill(ds);
                        Access.ClosedAccess();
                        return ds.Tables[0];

                    }
                    catch
                    {
                        Access.ClosedAccess();
                        return tbl;
                    }

                }
                public static Product GetProductdetail(Int32 product_id)
                {
                    Product myproduct = new Product();
                    //try {
                        Access.InitAccess();
                        Access.mySqlCommand.CommandText = "Sp_Products_GetProductDetail";
                        Access.mySqlCommand.Parameters.Add("@Products_Id", SqlDbType.Int).Value = product_id;
                        SqlDataReader myreader;
                        myreader = Access.mySqlCommand.ExecuteReader();
                        while (myreader.Read())
                        {
                                myproduct = new Product(Convert.ToInt32(myreader["Products_Id"]), myreader["Products_Name"].ToString(), myreader["Products_Title"].ToString(),
                                Convert.ToInt32(myreader["Products_Quantity"].ToString()), Convert.ToInt32(myreader["Products_Price"].ToString()), myreader["Products_Unit"].ToString(),
                                Convert.ToInt32(myreader["Class_Id"].ToString()), Convert.ToInt32(myreader["Brand_Id"].ToString()), Convert.ToInt32(myreader["Category_Id"].ToString()),
                                myreader["Products_Detail"].ToString(), myreader["Products_Warranty"].ToString(), myreader["Products_Image"].ToString(), myreader["Products_Origin"].ToString(), myreader["Products_DescriptionImage"].ToString(),
                                Convert.ToDateTime(myreader["Products_DateUpdate"].ToString()), Convert.ToBoolean(myreader["IsActive"].ToString()), Convert.ToBoolean(myreader["IsHot"].ToString()), Convert.ToBoolean(myreader["IsNew"].ToString()));
                        }
                        myreader.Close();
                        Access.ClosedAccess();
                        return myproduct;
                    //}

                    //catch {
                    //    Access.ClosedAccess();
                    //    return myproduct;
                    //}
                }
                public static DataTable GetProductSameBrand(Int32 brand_id,Int32 Products_Id)
                {
                    DataTable tbl = new DataTable();
                    try
                    {
                        Access.InitAccess();
                        Access.mySqlCommand.CommandText = "Sp_Products_GetProductSameBrand";
                        Access.mySqlCommand.Parameters.Add("@Brand_Id", SqlDbType.Int).Value = brand_id;
                        Access.mySqlCommand.Parameters.Add("@Products_Id", SqlDbType.Int).Value = Products_Id;
                        SqlDataAdapter da = new SqlDataAdapter(Access.mySqlCommand);
                        DataSet ds = new DataSet();
                        da.Fill(ds);
                        Access.ClosedAccess();
                        return ds.Tables[0];

                    }
                    catch
                    {
                        Access.ClosedAccess();
                        return tbl;
                    }

                }
                public static void GetCategoryHomepage(Repeater rp)
                {
                    //try {
                        Access.InitAccess();
                        Access.mySqlCommand.CommandText = "sp_Products_GetCategoryHomepage";
                        DataSet ds = new DataSet();
                        SqlDataAdapter da = new SqlDataAdapter(Access.mySqlCommand);
                        da.Fill(ds);
                        rp.DataSource = ds.Tables[0];
                        Access.ClosedAccess();
                        rp.DataBind();
                    //}
                    //catch {
                    //    Access.ClosedAccess();
                    //    return;
                    //}
                }
                public static void GetClassHomepage(Repeater rp)
                {
                    //try {
                    Access.InitAccess();
                    Access.mySqlCommand.CommandText = "sp_Products_GetClassHomepage";
                    DataSet ds = new DataSet();
                    SqlDataAdapter da = new SqlDataAdapter(Access.mySqlCommand);
                    da.Fill(ds);
                    rp.DataSource = ds.Tables[0];
                    Access.ClosedAccess();
                    rp.DataBind();
                    //}
                    //catch {
                    //    Access.ClosedAccess();
                    //    return;
                    //}
                }
                public static DataTable GetProductByCatalog(Int16 Category_Id)
                {
                    DataTable tbl=new DataTable();
                    //try
                    //{
                    //    Access.InitAccess();
                    //    Access.mySqlCommand.CommandText = "Sp_Products_GetProductHomepage";
                    //    Access.mySqlCommand.Parameters.Add("@Category_Id", SqlDbType.TinyInt).Value = Category_Id;
                    //    DataSet ds = new DataSet();
                    //    SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter(Access.mySqlCommand);
                    //    mySqlDataAdapter.Fill(ds, "GetProductByCatalog");
                    //    tbl=ds.Tables[0];
                    //    Access.ClosedAccess();
                    //    return tbl;
                     
                    //}
                    //catch (System.Exception)
                    //{
                    //    Access.ClosedAccess();
                    //    return tbl;
                    //}
                    tbl = Access.GetData("Sp_Products_GetProductHomepage", "@Category_Id", Category_Id, SqlDbType.TinyInt);
                    return tbl;
                }
                public static DataTable GetProductByClass(Int16 Class_Id)
                {
                    DataTable tbl = new DataTable();
                    //try
                    //{
                    //    Access.InitAccess();
                    //    Access.mySqlCommand.CommandText = "Sp_Products_GetProductByClass";
                    //    Access.mySqlCommand.Parameters.Add("@Class_Id", SqlDbType.Int).Value = Class_Id;
                    //    DataSet ds = new DataSet();
                    //    SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter(Access.mySqlCommand);
                    //    mySqlDataAdapter.Fill(ds, "GetProductByClass");
                    //    tbl = ds.Tables[0];
                    //    Access.ClosedAccess();
                    //    return tbl;

                    //}
                    //catch (System.Exception)
                    //{
                    //    Access.ClosedAccess();
                    //    return tbl;
                    //}
                    tbl = Access.GetData("Sp_Products_GetProductByClass", "@Class_Id", Class_Id, SqlDbType.Int);
                    return tbl;
                }
                public static void showbrandheader(Brand brand, Literal header)
                {
                    string headertext = "";
                    headertext += "<a href=\"http://localhost:2011/didong\">Trang chủ</a> »";
                    headertext += "<a href=\"http://localhost:2011/didong/page/san-pham.html\">Sản phẩm</a> »";
                    headertext += "<a href=\"http://localhost:2011/didong/brand/"+brand.Brand_Title+"\">"+ brand.Brand_Name+"</a> ";
                    header.Text = headertext;
                }
                public static DataTable GetProductNews()
                {
                    DataTable tbl = new DataTable();
                    tbl = Access.GetData("Sp_Products_GetProductNew");
                    return tbl;
                }
                public static Boolean DeleteProduct(int Product_Id)
                {
                    try
                    {
                        Access.InitAccess();
                        Access.mySqlCommand.CommandText = "Sp_Products_Delete";
                        Access.mySqlCommand.Parameters.Add("@Products_Id", SqlDbType.Int).Value = Product_Id;
                        int result = 0;
                        result = Convert.ToInt16(Access.mySqlCommand.ExecuteNonQuery());
                        Access.ClosedAccess();
                        if (result > 0) return true;
                        else return false;
                    }

                    catch
                    {
                        Access.ClosedAccess();
                        return false;
                    }
                }
                public static bool UpdateSimple(int Product_id, bool ishot, bool Isactive)
                {
                    bool result = false;
                    Access.InitAccess();
                    Access.mySqlCommand.CommandText = "Sp_Products_UpdateSimple";
                    Access.mySqlCommand.Parameters.Add("@Products_Id", SqlDbType.Int).Value = Product_id;
                    Access.mySqlCommand.Parameters.Add("@Ishot", SqlDbType.Bit).Value = ishot;
                    Access.mySqlCommand.Parameters.Add("@IsActive", SqlDbType.Bit).Value = Isactive;
                    try
                    {
                        Access.mySqlCommand.ExecuteNonQuery();
                        result = true;
                    }
                    catch
                    {
                    }
                    Access.ClosedAccess();
                    return result;
                }
                public static bool Update_Product( Product myproduct)
                {
                  //try{
                    Access.InitAccess();
                    Access.mySqlCommand.CommandText = "Sp_Products_Update";
                    Access.mySqlCommand.Parameters.Add("@Products_Id", SqlDbType.Int).Value =myproduct.Products_Id;
                    Access.mySqlCommand.Parameters.Add("@Products_Name", SqlDbType.NVarChar).Value = myproduct.Products_Name;
                    Access.mySqlCommand.Parameters.Add("@Products_Title", SqlDbType.NVarChar).Value =myproduct.Products_Title;
                    Access.mySqlCommand.Parameters.Add("@Products_Quantity", SqlDbType.Int).Value = myproduct.Products_Quantity;
                    Access.mySqlCommand.Parameters.Add("@Products_Unit", SqlDbType.NVarChar).Value =myproduct.Products_Unit;
                    Access.mySqlCommand.Parameters.Add("@Products_Price", SqlDbType.Int).Value =myproduct.Products_Price;
                    Access.mySqlCommand.Parameters.Add("@Products_Warranty", SqlDbType.NVarChar).Value =myproduct.Products_Warranty;
                    Access.mySqlCommand.Parameters.Add("@Products_Image", SqlDbType.NVarChar).Value =myproduct.Products_Image;
                    Access.mySqlCommand.Parameters.Add("@Products_DescriptionImage", SqlDbType.NVarChar).Value = myproduct.Products_DescriptionImage;
                    Access.mySqlCommand.Parameters.Add("@Products_Origin", SqlDbType.NVarChar).Value =myproduct.Products_Origin;
                    Access.mySqlCommand.Parameters.Add("@Products_Detail", SqlDbType.NVarChar).Value =myproduct.Products_Detail;
                    Access.mySqlCommand.Parameters.Add("@Category_Id", SqlDbType.Int).Value =myproduct.Category_Id;
                    Access.mySqlCommand.Parameters.Add("@Brand_Id", SqlDbType.Int).Value =myproduct.Brand_Id;
                    Access.mySqlCommand.Parameters.Add("@Class_Id", SqlDbType.Int).Value =myproduct.Class_Id;
                    Access.mySqlCommand.Parameters.Add("@Ishot", SqlDbType.Bit).Value =myproduct.Ishot;
                    Access.mySqlCommand.Parameters.Add("@IsActive", SqlDbType.Bit).Value =myproduct.IsActive;
                    Access.mySqlCommand.Parameters.Add("@IsNew", SqlDbType.Bit).Value = myproduct.IsNew;
                    int result=0;
                    result=Convert.ToInt16(Access.mySqlCommand.ExecuteNonQuery());
                    Access.ClosedAccess();
                    if(result>0) return true;
                    else return false;
                  //}
                  //catch
                  //{
                  //      Access.ClosedAccess();
                  //      return false;
                  //}
                    
                }
                public static bool Add_Product(Product myproduct)
                {
                    //try{
                    Access.InitAccess();
                    Access.mySqlCommand.CommandText = "Sp_Products_Add";
                    Access.mySqlCommand.Parameters.Add("@Products_Name", SqlDbType.NVarChar).Value = myproduct.Products_Name;
                    Access.mySqlCommand.Parameters.Add("@Products_Title", SqlDbType.NVarChar).Value = myproduct.Products_Title;
                    Access.mySqlCommand.Parameters.Add("@Products_Quantity", SqlDbType.Int).Value = myproduct.Products_Quantity;
                    Access.mySqlCommand.Parameters.Add("@Products_Unit", SqlDbType.NVarChar).Value = myproduct.Products_Unit;
                    Access.mySqlCommand.Parameters.Add("@Products_Price", SqlDbType.Int).Value = myproduct.Products_Price;
                    Access.mySqlCommand.Parameters.Add("@Products_Warranty", SqlDbType.NVarChar).Value = myproduct.Products_Warranty;
                    Access.mySqlCommand.Parameters.Add("@Products_Image", SqlDbType.NVarChar).Value = myproduct.Products_Image;
                    Access.mySqlCommand.Parameters.Add("@Products_DescriptionImage", SqlDbType.NVarChar).Value = myproduct.Products_DescriptionImage;
                    Access.mySqlCommand.Parameters.Add("@Products_Origin", SqlDbType.NVarChar).Value = myproduct.Products_Origin;
                    Access.mySqlCommand.Parameters.Add("@Products_Detail", SqlDbType.NVarChar).Value = myproduct.Products_Detail;
                    Access.mySqlCommand.Parameters.Add("@Category_id", SqlDbType.Int).Value = myproduct.Category_Id;
                    Access.mySqlCommand.Parameters.Add("@Brand_Id", SqlDbType.Int).Value = myproduct.Brand_Id;
                    Access.mySqlCommand.Parameters.Add("@Products_DateUpdate", SqlDbType.DateTime).Value = myproduct.Products_DateUpdate;
                    
                    Access.mySqlCommand.Parameters.Add("@Class_Id", SqlDbType.Int).Value = myproduct.Class_Id;
                    Access.mySqlCommand.Parameters.Add("@Ishot", SqlDbType.Bit).Value = myproduct.Ishot;
                    Access.mySqlCommand.Parameters.Add("@IsActive", SqlDbType.Bit).Value = myproduct.IsActive;
                    Access.mySqlCommand.Parameters.Add("@IsNew", SqlDbType.Bit).Value = myproduct.IsNew;
                    int result = 0;
                    result = Convert.ToInt16(Access.mySqlCommand.ExecuteNonQuery());
                    Access.ClosedAccess();
                    if (result > 0) return true;
                    else return false;
                    //}
                    //catch
                    //{
                    //      Access.ClosedAccess();
                    //      return false;
                    //}

                }
                public static DataTable GetProductConditon(string query)
                {
                    DataTable tbl = new DataTable();
                    try
                    {
                        Access.InitAccess();
                        Access.mySqlCommand.CommandText = "Sp_Products_GetProductsByCondition";
                        Access.mySqlCommand.Parameters.Add("@Query", SqlDbType.NVarChar).Value = query;
                        DataSet ds = new DataSet();
                        SqlDataAdapter da = new SqlDataAdapter(Access.mySqlCommand);
                        da.Fill(ds);
                        tbl = ds.Tables[0]; ;
                        Access.ClosedAccess();
                        return tbl;
                    }
                    catch {
                        Access.ClosedAccess();
                        return tbl;
                    
                    }
                    
                }
                public static DataTable GetProductByName(string query)
                {
                    DataTable tbl = new DataTable();
                    try
                    {
                        Access.InitAccess();
                        Access.mySqlCommand.CommandText = "Sp_product_SearchByName";
                        Access.mySqlCommand.Parameters.Add("@StringName", SqlDbType.NVarChar).Value = query;
                        DataSet ds = new DataSet();
                        SqlDataAdapter da = new SqlDataAdapter(Access.mySqlCommand);
                        da.Fill(ds);
                        tbl = ds.Tables[0]; ;
                        Access.ClosedAccess();
                        return tbl;
                    }
                    catch
                    {
                        Access.ClosedAccess();
                        return tbl;

                    }

                }
                public static Int16 DeleteproductNotorder()
                {
                    try
                    {
                        Access.InitAccess();
                        Access.mySqlCommand.CommandText = "Sp_Products_Product_deleteByNotOrder";
                        Int16 result = Convert.ToInt16(Access.mySqlCommand.ExecuteNonQuery());
                        Access.ClosedAccess();
                        if (result > 0)
                        {
                            return result;
                        }
                        else
                        {
                            return -1;
                        }
                    }
                    catch
                    {
                        Access.ClosedAccess();
                        return -1;
                    }
                }
                public static DataTable hoadon( int hoadon)
                {
                    DataTable tbl = new DataTable();
                    //try
                    //{
                        Access.InitAccess();
                        Access.mySqlCommand.CommandText = "Sp_Orders_GetOrderDetail";
                        Access.mySqlCommand.Parameters.Add("@Order_Id", SqlDbType.Int).Value = hoadon;
                        DataSet ds = new DataSet();
                        SqlDataAdapter da = new SqlDataAdapter(Access.mySqlCommand);
                        da.Fill(ds);
                        tbl = ds.Tables[0];
                        Access.ClosedAccess();
                    
                        return tbl;
                    //}
                    //catch {
                    //    Access.ClosedAccess();
                    //    return tbl;
                    //}
                }
                public static DataTable ReportSellByDay(DateTime Ngay)
                {
                    DataTable tbl = new DataTable();
                    try {
                        Access.InitAccess();
                        Access.mySqlCommand.CommandText = "Sp_ReportSellByDay";
                        Access.mySqlCommand.Parameters.Add("@DateSell", SqlDbType.DateTime).Value = Ngay;
                        DataSet ds = new DataSet();
                        SqlDataAdapter da = new SqlDataAdapter(Access.mySqlCommand);
                        da.Fill(ds);
                        Access.ClosedAccess();
                        return ds.Tables[0];
                    }
                    catch {
                        Access.ClosedAccess();
                        return tbl;
                    }
                }
                public static Int32 AddOrderImport(OrderImport myorder)
                {
                    //try
                    //{
                        Int16 result = 0;
                        Int32 Order_Id = 0;
                        Access.InitAccess();
                        Access.mySqlCommand.CommandText = "Sp_Order_Import_Add";
                        Access.mySqlCommand.Parameters.Add("@Supply_Id", SqlDbType.Int).Value = myorder.Supply_Id;
                        Access.mySqlCommand.Parameters.Add("@Order_Date", SqlDbType.DateTime).Value = myorder.Order_Date;
                        Access.mySqlCommand.Parameters.Add("@Toltal", SqlDbType.Decimal).Value = 232323;
                        Access.mySqlCommand.Parameters.Add("Quantity", SqlDbType.Int).Value = 33;
                        Access.mySqlCommand.Parameters.Add("@Notice", SqlDbType.NVarChar).Value = myorder.Notice;
                        Access.mySqlCommand.Parameters.Add("@People_Name", SqlDbType.NVarChar).Value = myorder.People_Name;
                        Order_Id = Convert.ToInt32(Access.mySqlCommand.ExecuteScalar());
                        if (Order_Id < 1)
                        {
                            Access.ClosedAccess();
                            return -1;
                        }
                        else
                        {
                            foreach (SelectedProduct mycart in myorder.Item)
                            {
                                Access.mySqlCommand.Parameters.Clear();
                                Access.mySqlCommand.CommandText = "Sp_Order_ImportDetail_Add";
                                Access.mySqlCommand.Parameters.Add("@Products_Id", SqlDbType.Int).Value = mycart.Id;
                                Access.mySqlCommand.Parameters.Add("@Products_Name", SqlDbType.NVarChar).Value = mycart.Name;
                                Access.mySqlCommand.Parameters.Add("@Quantity", SqlDbType.Int).Value = mycart.Quantity;
                                Access.mySqlCommand.Parameters.Add("@Total", SqlDbType.Decimal).Value = mycart.SubTotal;
                                Access.mySqlCommand.Parameters.Add("@Unit", SqlDbType.NVarChar).Value = mycart.Unit;
                                result = Convert.ToInt16(Access.mySqlCommand.ExecuteNonQuery());
                                if (result != 1)
                                {
                                    Access.mySqlCommand.Parameters.Clear();
                                    Access.mySqlCommand.CommandText = "Sp_OrderImport_DeleteOrder";
                                    Access.mySqlCommand.Parameters.Add("@Order_Id", SqlDbType.Int).Value = Order_Id;
                                    Access.mySqlCommand.ExecuteNonQuery();
                                    Access.ClosedAccess();
                                    return -1;
                                }
                            }
                            Access.ClosedAccess();
                            return Order_Id;
                                
                          }
                    //}                    
                    //catch
                    //{
                    //    Access.ClosedAccess();
                    //    return -1;

                    //}
                }
        #endregion
    }
}
